package com.taotao.wechat.game;

import com.taotao.admin.MyRopClient;
import com.taotao.wechat.message.resp.Article;
import com.taotao.wechat.message.resp.BaseMessage;
import com.taotao.wechat.message.resp.NewsMessage;
import com.taotao.wechat.util.MessageUtil;
import com.taotao.wechat.util.ValidateUtil;

import java.util.ArrayList;
import java.util.List;

public class FlopGame extends Game {
    public static final boolean IS_ENABLE = false;

    private static final String FORMAT_GAME_URL = MyRopClient.BASE_URL + "/game/flop/flopGamePage.html?appId=%s&openId=%s&tel=%s";
    private static final String RESPONSE_GAME_URL_TITLE = "年底大转运，微厅来翻牌";
    private static final String RESPONSE_GAME_URL_IMAGE = "http://103.227.80.253/gameImages/flop_news_image.jpg";
    private static final String RESPONSE_GAME_URL_DESCRIPTION = "进入翻牌游戏页面参加翻牌赢话费活动，每个内蒙古移动用户每日可以参加一次，所得话费可累加，直到活动结束。";

    private static final String WECHAT_ALREADY_JOIN = "您今天的2次机会已用完，欢迎明天再来！";
    private static final String TEL_ALREADY_JOIN = "此手机号码已经被别人占用,请更换手机号码参与活动。";

    public FlopGame(BaseMessage baseMessage, String content, String appKey) {
        super(baseMessage, content, appKey);
    }

    @Override
    public String wechatJoinCountToday(String openId, String appKey) {
        if (ValidateUtil.hasJoinToday(appKey, openId) == ValidateUtil.NO_COUNT) {
            return WECHAT_ALREADY_JOIN;
        }
        return "";
    }

    @Override
    public String telJoinCountToday(String tel, String openId, String appKey) {
        if (ValidateUtil.hasTelJoinCountToday(tel, appKey, openId) == ValidateUtil.NO_COUNT) {
            return TEL_ALREADY_JOIN;
        }
        return "";
    }

    @Override
    protected String gameUrl() {
        String url = String.format(FORMAT_GAME_URL, appKey, baseMessage.getToUserName(), content);
        NewsMessage newsMessage = new NewsMessage(baseMessage);
        newsMessage.setMsgType(MessageUtil.RESP_MESSAGE_TYPE_NEWS);
        newsMessage.setArticleCount(1);
        Article article = new Article();
        article.setDescription(RESPONSE_GAME_URL_DESCRIPTION);
        article.setPicUrl(RESPONSE_GAME_URL_IMAGE);
        article.setTitle(RESPONSE_GAME_URL_TITLE);
        article.setUrl(url);
        List<Article> articles = new ArrayList<Article>();
        articles.add(article);
        newsMessage.setArticles(articles);
        return MessageUtil.newsMessageToXml(newsMessage);
    }

    @Override
    public String getAppIds() {
        return "wx8010a0acb61a2948";
    }

    @Override
    public String getMemberCode() {
        return "sdkl2015";
    }

    @Override
    public Integer getMemberStatus() {
        return 3;
    }

    @Override
    public String getName() {
        return "翻牌";
    }

    @Override
    public String getNickName() {
        return "flop";
    }

    @Override
    public String getStartDate() {
        return "2014-12-01";
    }

    @Override
    public String getEndDate() {
        return "2015-01-01";
    }
}
